package com.egao.common.manage.school;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.company.constants.CheckRecordConstants;
import com.egao.common.module.company.entity.vo.PreachCloudFormVO;
import com.egao.common.module.company.entity.vo.PreachCloudListVO;
import com.egao.common.module.company.service.PreachCloudService;
import com.egao.common.module.push.service.PositionMatchingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Map;

/**
 * 学校空中宣讲会管理
 * @author dl
 */
@Api(tags = "学校空中宣讲会管理")
@RestController
@RequestMapping("${api}")
public class SchoolPreachCloudController extends BaseController {

    @Autowired
    private PreachCloudService preachCloudService;

    @Autowired
    private PositionMatchingService positionMatchingService;

    @PreAuthorize("hasAuthority('school:preachcloud:list')")
    @ApiOperation(value = "空中宣讲会信息", notes = "未审核状态升序 创建时间倒序")
    @OperLog(value = "空中宣讲会信息", desc = "分页查询空中宣讲会信息")
    @ApiPageParam
    @GetMapping("/school/preach-cloud/page")
    public PageResult<PreachCloudListVO> page(HttpServletRequest request) {
        PageParam<PreachCloudListVO> pageParam = new PageParam<>(request);
        return new PageResult<>(preachCloudService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:preachcloud:check')")
    @OperLog(value = "审核空中宣讲会信息", desc = "审核空中宣讲会信息", result = true)
    @ApiOperation(value = "审核空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "preachCloudFormVO")
    })
    @PutMapping("/school/preach-cloud/check")
    public JsonResult check(@Valid @RequestBody PreachCloudFormVO preachCloudFormVO) {
        preachCloudFormVO.setCheckUserId(getLoginUserId());
        return preachCloudService.checkPreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('school:preachcloud:delete')")
    @OperLog(value = "删除空中宣讲会信息", desc = "删除空中宣讲会信息", result = true)
    @ApiOperation(value = "删除空中宣讲会信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preachCloudFormVO", value = "preachCloudFormVO", required = true, dataType = "preachCloudFormVO")
    })
    @PutMapping("/school/preach-cloud/delete")
    public JsonResult deletePreachCloud(@RequestBody PreachCloudFormVO preachCloudFormVO) {
        return preachCloudService.removePreachCloud(preachCloudFormVO);
    }

    @PreAuthorize("hasAuthority('school:preachcloud:detail')")
    @ApiOperation(value = "获取空中宣讲会信息详情")
    @OperLog(value = "获取空中宣讲会信息详情", desc = "获取空中宣讲会信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "空中宣讲会信息id", required = true, dataType = "int")
    })
    @GetMapping("/school/preach-cloud/detail")
    public JsonResult detail(Integer id) {
        return preachCloudService.detail(id);
    }

    @PreAuthorize("hasAuthority('school:preachcloud:detail')")
    @ApiOperation(value = "获取职位推荐统计")
    @OperLog(value = "获取职位推荐统计", desc = "获取职位推荐统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "宣讲会信息id", required = true, dataType = "int")
    })
    @GetMapping("/school/preach-cloud/push-total")
    public JsonResult getTotal(Integer id) throws IOException {
        return positionMatchingService.getTotal(id, CheckRecordConstants.CHECK_PREACH_CLOUD);
    }

    @PreAuthorize("hasAuthority('school:preachcloud:check')")
    @OperLog(value = "空中宣讲会信息", desc = "导出空中宣讲会信息")
    @ApiOperation(value = "导出空中宣讲会信息")
    @GetMapping("/school/preach-cloud/export")
    public void export(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> pageParam = new PageParam<>(request).getNoPageParam();
        preachCloudService.exportExcel(pageParam, response);
    }
}
